package net.schmurgon.gwt.scaffold.generated;

import com.google.gwt.app.place.AbstractRecordListView;
import com.google.gwt.app.place.PropertyColumn;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormatRenderer;
import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import net.schmurgon.gwt.request.SeriesRecord;
import net.schmurgon.gwt.request.CourseRecord;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link AbstractRecordListView} specialized to {@link SeriesKey}} values.
 */
public class SeriesListView extends AbstractRecordListView<SeriesRecord> {
	interface Binder extends UiBinder<HTMLPanel, SeriesListView> {
	}

	private static final Binder BINDER = GWT.create(Binder.class);

	@UiField CellTable<SeriesRecord> table;
	@UiField Button newButton;
  
	public SeriesListView() {
		init(BINDER.createAndBindUi(this), table, newButton, getColumns());
	}

	protected List<PropertyColumn<SeriesRecord, ?>> getColumns() {
		// TODO These should be <g:col> elements in a <g:table> in the ui.xml file

		List<PropertyColumn<SeriesRecord, ?>> columns = new ArrayList<PropertyColumn<SeriesRecord, ?>>();
		
	    columns.add(new PropertyColumn<SeriesRecord, net.schmurgon.gwt.request.CourseRecord>(SeriesRecord.longCourse, net.schmurgon.gwt.scaffold.generated.CourseRecordRenderer.instance()));
	    columns.add(new PropertyColumn<SeriesRecord, java.lang.String>(SeriesRecord.seriesName, new AbstractRenderer<java.lang.String>() {
      public String render(java.lang.String obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));
	    columns.add(new PropertyColumn<SeriesRecord, net.schmurgon.gwt.request.CourseRecord>(SeriesRecord.shortCourse, net.schmurgon.gwt.scaffold.generated.CourseRecordRenderer.instance()));		
	    return columns;
	}
}
